package com.kkagr.netty.firstExample;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

public class TestNettyServerDecoder extends LengthFieldBasedFrameDecoder {
    private  int localport;
    public TestNettyServerDecoder(int localPort){
        super(2*1024*1024, 0, 4,0,0);
        this.localport=localPort;

    }
    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {

        ByteBuf frame = (ByteBuf) super.decode(ctx, in);
        if (frame == null) {
            return null;
        }
        int length = frame.readInt();
        byte[] msg = new byte[length];
        frame.readBytes(msg);
       // ProxyMessage proxyMessage = ProxyMessageUtil.decode(msg);
      //  frame.release();
       // return proxyMessage;
        return msg;
    }
}
